package com.lxy.controller.admin;



import com.lxy.common.constant.HttpStatus;
import com.lxy.common.domain.AjaxResult;
import com.lxy.entity.Spu;
import com.lxy.feign.SkuFeignClient;
import com.lxy.mapper.SpuMapper;
import com.lxy.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "spu商品管理")
@RestController
@RequestMapping("/api")
public class SpuController implements SkuFeignClient {

    @Autowired
    SpuService spuService;



    @ApiOperation(value = "保存Spu")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Spu spu){
        boolean save = spuService.save(spu);
        if (save){
            return AjaxResult.success("添加成功",save);
        }else {
            return AjaxResult.error("保存失败");
        }
    }

    @GetMapping("/query")
    @ApiOperation(value = "spuId查询商品")
    @Override
    public AjaxResult queryBySkuId(Long skuId) {
        Spu spu = spuService.queryBySpuId(skuId);
        return new AjaxResult<>(HttpStatus.SUCCESS,"返回成功",spu);
    }
}
